﻿using System.Collections.Generic;

namespace Gem
{
    /// <summary>
    /// A definition for an SCC environment. This defines a monitor on a local folder.
    /// </summary>
    public class EnvironmentDefinition
    {
        public EnvironmentDefinition(ISccProvider sccProvider)
        {
            SccProvider = sccProvider;
            IsViewable = true;
        }

        /// <summary>
        /// Gets the related SCC provider.
        /// </summary>
        public ISccProvider SccProvider { get; }

        /// <summary>
        /// Gets the monitored folder name.
        /// </summary>
        public string FolderName => SccProvider.LocalFolderName;

        /// <summary>
        /// Gets SCC-related information about this environment.
        /// </summary>
        public string FolderSccInformation => SccProvider.FolderContentTitle;

        /// <summary>
        /// Gets or sets additional custom information about this environment.
        /// </summary>
        public string FolderCustomInformation { get; set; }

        public string EnvironmentInfo => ToString();

        // The properties in this region may not belong in this model-type, but it's the easy way.
        // TODO: Refactor to another mechanism conveying the view-only information to/from the configuration.
        #region Properties for saving view-only related-information.

        /// <summary>
        /// Gets or sets whether this environment item is viewable.
        /// For passing view information to the configuration.
        /// </summary>
        public bool IsViewable { get; set; }

        #endregion

        public override string ToString()
        {
            var infoList = new List<string>
            {
                FolderName,
                FolderSccInformation,
            };

            if (!string.IsNullOrEmpty(FolderCustomInformation))
            {
                infoList.Add(string.Format("[{0}]", FolderCustomInformation));
            }

            return string.Join(" | ", infoList);
        }
    }
}
